package com.example.wearing.tools;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.wearing.R;
import com.example.wearing.javabean.Clothes;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/3/17.
 */
public class ClothesListAdapter extends ArrayAdapter {

    Context context;
    ArrayList<Clothes> clothesList;
//    private int nowSelectedIndex = 0;

    private static final String TAG = "ClothesListAdapter";
    public ClothesListAdapter(Context context,
                           int resource,
                           ArrayList<Clothes> list) {
        super(context, resource, list);
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        View itemView = convertView;
        if (itemView == null) {
            itemView = LayoutInflater.from(getContext()).inflate(R.layout.clothes_list,
                    parent,
                    false);
        }

        Clothes clothes = (Clothes) getItem(position);
        TextView clothesName = (TextView) itemView.findViewById(R.id.clothesName);
        ImageView clothesImg = (ImageView) itemView.findViewById(R.id.clothesImg);

        clothesName.setText(clothes.getC_name());
        String imgStr = clothes.getC_img();
        Bitmap bitmap = ImageUtil.base64ToImage(imgStr);
        clothesImg.setImageBitmap(bitmap);
        return  itemView;
    }


}
